﻿using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NTmdb.TestProject
{
    /// <summary>
    ///     This is a test class for TmdbReviewTest and is intended
    ///     to contain all TmdbReviewTest Unit Tests
    /// </summary>
    [TestClass]
    public class TmdbReviewTest
    {
        /// <summary>
        ///     A test for TmdbReview Constructor
        /// </summary>
        [TestMethod]
        public void TmdbReviewConstructorTest()
        {
            var target = new TmdbReview();
            Assert.IsNotNull( target );
        }

        /// <summary>
        ///     A test for Iso639_1
        /// </summary>
        [TestMethod]
        public void Iso639_1Test()
        {
            var target = new TmdbReview();
            string expected = Guid.NewGuid().ToString();
            string actual;
            target.Iso639_1 = expected;
            actual = target.Iso639_1;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for MediaId
        /// </summary>
        [TestMethod]
        public void MediaIdTest()
        {
            var target = new TmdbReview();
            int expected = new Random().Next( 0, Int32.MaxValue );
            int actual;
            target.MediaId = expected;
            actual = target.MediaId;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for MediaTitle
        /// </summary>
        [TestMethod]
        public void MediaTitleTest()
        {
            var target = new TmdbReview();
            string expected = Guid.NewGuid().ToString();
            string actual;
            target.MediaTitle = expected;
            actual = target.MediaTitle;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for MediaType
        /// </summary>
        [TestMethod]
        public void MediaTypeTest()
        {
            var target = new TmdbReview();
            string expected = Guid.NewGuid().ToString();
            string actual;
            target.MediaType = expected;
            actual = target.MediaType;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Serialize & Deserialize
        /// </summary>
        [TestMethod]
        [DeploymentItem(@"..\..\TestData\movieReview.json.txt")]
        public async Task SerializeDeserializeTest()
        {
            var target = new TmdbReview();
            var jsonContent = File.ReadAllText("movieReview.json.txt");
            var actual = await target.DeserializeJson<TmdbReview>(jsonContent);

            Assert.AreEqual("50cf0340760ee310f513d014", actual.Id);
            Assert.AreEqual("Andres Gomez", actual.Author);
            Assert.AreEqual("Peter Jackson creates the same world that he already shown us in the LOTR, but that's not the only thing he repeats.\r\n\r\nHe also repeats ripping Tolkiens book into a sucession of endless races and actions scenes with orcs falling everywhere and several \"inventions\" that mess the beautiful story created by the English author.\r\n\r\nHe also repeats those several minutes of platform game inside caves that we saw in Moria and in his version of King Kong.\r\n\r\nIf you loved the previous movies from Jackson, you will love this too.\r\n\r\nIf you are looking for some quality, you will only finding in the re-creation of the Middle Earth and the peformances of Ian McKellen, Martin Freeman and Cate Blanchett.", actual.Content);
            Assert.AreEqual("en", actual.Iso639_1);
            Assert.AreEqual(49051, actual.MediaId);
            Assert.AreEqual("The Hobbit: An Unexpected Journey", actual.MediaTitle);
            Assert.AreEqual("Movie", actual.MediaType);
            Assert.AreEqual("http://j.mp/U5YqN2", actual.Url);
        }
    }
}